
package net.ddns.xcyyds.kungfu;

import net.minecraft.world.entity.player.Player;
import org.lwjgl.glfw.GLFW;

import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.client.event.InputEvent;
import net.minecraftforge.client.ClientRegistry;
import net.minecraftforge.api.distmarker.Dist;

import net.minecraft.client.Minecraft;
import net.minecraft.client.KeyMapping;




@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, value = {Dist.CLIENT})
public class KungFuModMouseMappings {
	public static final KeyMapping MOUSE0 = new KeyMapping("key.kung_fu.mouseleft", GLFW.GLFW_MOUSE_BUTTON_1, "key.categories.kungfu");
	public static final KeyMapping MOUSE1 = new KeyMapping("key.kung_fu.mouseright", GLFW.GLFW_MOUSE_BUTTON_2, "key.categories.kungfu");



	@SubscribeEvent
	public static void registerKeyBindings(FMLClientSetupEvent event) {
		ClientRegistry.registerKeyBinding(MOUSE0);
		ClientRegistry.registerKeyBinding(MOUSE1);

	}

	@Mod.EventBusSubscriber({Dist.CLIENT})
	public static class KeyEventListener {
		@SubscribeEvent
		public static void onKeyInput(InputEvent.MouseInputEvent event) {
			Player player = Minecraft.getInstance().player;
			if (player == null){return;}
			if (Minecraft.getInstance().screen == null) {//没有GUI


				if (event.getButton() == MOUSE0.getKey().getValue()) {
					if (event.getAction() == GLFW.GLFW_PRESS) {
						KungFuMod.PACKET_HANDLER.sendToServer(new Mouse0(0, 0));
						Mouse0.pressAction(player, 0, 0);
					}
				}



				if (event.getButton() == MOUSE1.getKey().getValue()) {
					if (event.getAction() == GLFW.GLFW_PRESS) {
						KungFuMod.PACKET_HANDLER.sendToServer(new Mouse1(0, 0));
						Mouse1.pressAction(player, 0, 0);
					}
				}







			}
		}
	}
}
